package com.cmap;

import java.util.concurrent.atomic.AtomicInteger;

public class CASTest {


    public static void main(String[] args) {

         AtomicInteger atomicInteger = new AtomicInteger(10);
        /**
         * 一个是期望值，一个是更新值，但期望值和原来的值相同时，才能够更改
         */
        System.out.println(atomicInteger.compareAndSet(10, 2020) + "\t当前的值为:" + atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(10, 2021) + "\t当前的值为:" + atomicInteger.get());
    }
}

